const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017/h5-2109')
const db = mongoose.connection

db.on('open', () => {
    console.log('数据库连接成功');
})
db.on('error', () => {
    console.log('数据库连接失败');
})

//获取Schema构造函数
const Schema = mongoose.Schema


const userSchema = new Schema({
    account: String,
    password: String,
    email: String,
    userText: [{
        userid: String,
        id: String,
        path: String,
        text: String,
        time: Date,
        imgUrl: String
    }],
    watched: []
})


//生成构造函数
const User = mongoose.model('User', userSchema)





//导出操作数据库的构造函数
module.exports = {
    User
}
